
#include "text.h"
#include <QFile>
#include <QDebug>
#include <iostream>


text::text(QObject *parent)
    : QObject{parent}
{
    length = 0;
    col = 0;
    map = nullptr;
}
text::~text()
{
    clear();
}


void text::InitByFile(QString fileName)
{
    QFile file(fileName);//创建文件对象
    file.open(QIODevice::ReadOnly);

    //读取内容
    QByteArray arrALL = file.readAll();
    arrALL.replace("\r\n","\n");
    QList<QByteArray> NoteList = arrALL.split('\n');
    length = NoteList.size();//确定谱面长度
    map = new int*[length];

    for(int i=0;i<length;i++)
    {
        QList<QByteArray> collist = NoteList[i].split(',');
        col = collist.size();
        map[i] = new int[col];

        for (int j=0;j<col;j++)
        {
            map[i][j] = collist[j].toInt();

        }
    }

    qDebug() << "...";
}



void text::clear()
{
    if(map != nullptr)
    {
        for(int i=0;i<length;i++)
        {
            delete[] map[i];
        }
        delete[] map;
    }
}
